package com.ibeeking.found.upms.s.rest.controller.v1.feign;

import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.db.annotation.IgnoreDS;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.found.common.entity.LoginUserDTO;
import com.ibeeking.found.common.entity.UserInfoDTO;
import com.ibeeking.found.upms.api.common.query.AccountLoginQuery;
import com.ibeeking.found.upms.s.rest.service.IShopUserService;
import com.ibeeking.found.upms.service.common.vo.ChoiceShopVO;
import com.ibeeking.nematos.utils.data.Collections3;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName UserController控制器
 * @Description 全局用户管理
 * @Author ibeeking
 * @Date 2020-12-02 15:29
 **/
@RestController
@RequestMapping("/b/user/feign/v1")
public class ShopUserFeignController {

    @Resource
    private IShopUserService userServiceImpl;

    /**
     * 根据登录账号查询登录用户信息
     *
     * @param query
     * @return
     */
    @IgnoreDS
    @PostMapping(value = "/queryAccountLogin")
    public LoginUserDTO queryAccountLogin(@RequestBody AccountLoginQuery query) {
        return userServiceImpl.queryAccountLogin(query);
    }

    @IgnoreDS
    @PostMapping(value = "/queryShopIds/{userId}")
    public List<Long> queryShopIds(@PathVariable("userId") Long userId) {
        return userServiceImpl.queryShopIds(userId);
    }

    @IgnoreDS
    @PostMapping(value = "/queryHaveShopId")
    public List<Long> queryHaveShopId(@LoginUser CurrentUser currentUser) {
        List<ChoiceShopVO> shops = userServiceImpl.shops(currentUser);
        if (Collections3.isEmpty(shops)) {
            return Collections3.emptyList();
        }
        return shops.stream().map(ChoiceShopVO::getId).collect(Collectors.toList());
    }

    @PostMapping(value = "/queryLoginUser/{userId}")
    public UserInfoDTO queryLoginUser(HttpServletRequest request, @PathVariable("userId") Long userId) {
        return userServiceImpl.queryLoginUser(request, userId);
    }
}
